package com.student.demo.controller;

import com.student.demo.entiy.Message;
import com.student.demo.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
public class messageController {
    @Autowired  // 自动注入
    private MessageService messageService;

    @PostMapping("/add")  // 添加一条留言
    public List<Message> add(String userName, String message) { // 返回要留言的用户名和留言内容
        System.out.println(userName + "sadfasd");
        Message messages = new Message(userName, message);
        messageService.addMessage(messages);
        return messageService.queryMessage();
    }

    @PostMapping("/display")
    public List<Message> display() {
        return messageService.queryMessage();
    }
}
